import React from 'react';
import { useSelector } from 'react-redux';
import { RootState } from '../store';

interface HasPermissionProps {
  code: string;
  children: React.ReactNode;
}

const HasPermission: React.FC<HasPermissionProps> = ({ code, children }) => {
  const buttonPermissions = useSelector((state: RootState) => state.auth.buttonPermissions);
  if (!buttonPermissions.includes(code)) return null;
  return <>{children}</>;
};

export default HasPermission; 